# 鼠标拖动-drag_and_drop()
# 鼠标悬停-move_to_element()
"""
# 拖动关键点分析
1. 源元素 source = driver.find_element_by_id(xxx)
2. 目标元素 target = driver.find_element_by_id(xxx)
3. 调用方法 action.drag_and_drop(source, target).perform()
"""
import time

from selenium import webdriver
from selenium.webdriver import ActionChains

# 浏览器：
driver = webdriver.Chrome()
# 输入访问地址URL ：
# url = r"C:\Users\19004\PycharmProjects\UI自动化测试\drop.html"
# driver.get(url)
driver.get(r"C:\Users\19004\PycharmProjects\UI自动化测试\drop.html")

# 放大浏览器 max
driver.maximize_window()

# 实例化并获取ActionChains类
action = ActionChains(driver)
# 获取源元素
source = driver.find_element_by_css_selector("#div1")
# 获取目标元素
target = driver.find_element_by_css_selector("#div2")
# 暂停3秒
time.sleep(3)
action.drag_and_drop(source, target).perform()

time.sleep(3)
# 关闭
driver.quit()